package com.qfedu.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.dao.AnimalDao;
import com.qfedu.dao.UserDao;
import com.qfedu.dto.AnimalDto;
import com.qfedu.entity.Animal;
import com.qfedu.entity.User;
import com.qfedu.service.intf.AnimalService;
import com.qfedu.service.intf.UserService;
import com.qfedu.vo.PageVo;
import com.qfedu.vo.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserDao dao;
    @Override
    public R save(User user) {
        if (dao.addUser(user) > 0) {
           return R.ok();
        }else {
           return R.fail();
        }
    }

    @Override
    public R update(User user) {
        if (dao.upDataUser(user) > 0) {
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public R delete(int id) {
        if (dao.delUser(id) > 0) {
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public PageVo queryPage(String username,int page, int limit) {
        PageHelper.startPage(page, limit);
        PageInfo<User> pageInfo = new PageInfo<>(dao.selectAll(username));
        return PageVo.ok(pageInfo.getTotal(),pageInfo.getList());
    }

    public User logincheck(String username,String password) {
        return dao.logincheck(username,password);
    }
}
